package com.lin.filter;

import com.lin.mapper.UserMapper;
import com.lin.utils.JWTUtil;
import io.jsonwebtoken.Claims;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.annotation.Resource;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 时间：2023/8/20
 */

public class MyOncePerRequestFilter extends OncePerRequestFilter {

    @Resource
    private AuthenticationManager authenticationManager;

    @Resource
    private UserMapper userMapper;

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

        String token = request.getHeader("token");
        if (token == null) {//还未认证
            filterChain.doFilter(request, response);
            return;
        }
        //解析token--成功解析token代表合法
        Claims parse = JWTUtil.parse(token);
        if(parse!=null){
            filterChain.doFilter(request, response);
        }

    }


}
